package com.wuyong;

import sun.awt.windows.ThemeReader;

public class Main {

    private static  Thread thread;

    public static void main(String[] args) {
        testThread();
        System.out.println("args = [" + thread.getState() + "  " + thread.isInterrupted() + "]");
        thread.interrupt();
        System.out.println("args = [" + thread.getState() + "  " + thread.isInterrupted() + "]");
    }

    public static void testThread() {
        thread =  new Thread(new Runnable() {
            @Override
            public void run() {

                int i = 0;
                while (!Thread.currentThread().isInterrupted() && i < 1000) {

                    System.out.println("---------  " + i);
                    try {
                        double d = 1000/i;
                        i++;
                    } catch (Exception e) {
                        System.out.println("---------  e :  " + e.getMessage());
                    }

                }

            }
        });
        thread.start();
        thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread t, Throwable e) {
                System.out.println("---------  e :  " + e.getMessage());
            }
        });

        Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread t, Throwable e) {
                System.out.println("---------  e :  " + e.getMessage());
            }
        });
    }
}
